﻿@model VaccineEbook.Models.DBEntity.Vaccine

<div class="modal-dialog" id="my-dialog">
    <form method="post" class="modal-content" action="@Url.Action("EditVaccine", "Vaccine")">
        <!-- Modal content-->
        <div class="modal-header">
            <a class="close" data-dismiss="modal">&times;</a>
            @if (Model.VaccineID == 0) { 
                <h3>Add Vaccine</h3>
            }
            else
            {
                <h4>Edit Vaccine: </h4>
                <h3>@Model.VaccineName</h3>
            }
        </div>
        <div class="modal-body">
            @Html.ValidationSummary(true)
            @Html.AntiForgeryToken()
            @Html.HiddenFor(model => model.VaccineID)
            <div>
                <div class="row">
                    <label class="col-xs-12 col-md-4 control-label">Vaccine name</label>
                    <div class="col-xs-12 col-md-8">
                        @Html.TextBoxFor(model => model.VaccineName, new { @class="form-control", placeholder="Name" })
                    </div>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <a href="#" class="btn" data-dismiss="modal">Close</a>
            <button type="submit" class="btn btn-primary">Save</button>
        </div>
    </form>
</div>

<script>
    // ajax submit
    $('form').submit(function () {
        //if ($(this).valid()) {
        $.ajax({
            url: this.action,
            type: this.method,
            data: $(this).serialize(),
            success: function (result) {
                // thành công load lại trang
                if (result.success) {
                    location.reload(true);
                }
                else {
                    // thất bại hiển thị lại
                    $('#my-dialog').parent().html(result);
                }
            }
        });
        //}
        return false;
        });
</script>